//引入样式
require('../css/commonCss/normalize.css')
require('../css/commonCss/reset.css')
require('../css/commonCss/property.css')
require('../css/commonCss/basic.less')
require('../fonts/iconfont.css')
// swiper
require('../libs/swiper/css/swiper-bundle.css')
//引入axios
const axios = require('axios')
//weui—插件库
require('weui')
const weui = require('weui.js')
// 导入util js
const util = require('../util/util.js')

const Swiper = require('../libs/swiper/JS/swiper-bundle.js')
// console.log(Swiper);
require('../css/home.less')


// 文档加载事件
document.addEventListener('DOMContentLoaded', function () {
  // 0:获取元素
  const rank  = document.querySelector('#rank')
  const punchDay  = document.querySelector('#punchDay')
  const todayPunch  = document.querySelector('#todayPunch')
  const badge  = document.querySelector('#badge')
  /* 
    0:底部导航
  */
  util.fixBottomNav('home');

  // 1：swiper轮播
  function SwiperAttr() {
    // 广告轮播图效果
    var mySwiper = new Swiper('.swiper', {
      autoplay: {
        delay: 1500,
        disableOnInteraction: false //不用禁止自动播放
      },
      loop: true,//无限循环
      pagination: {
        el: '.swiper-pagination',
        clickable: true,//点击分页器
      },//分页器

    })

  }
  SwiperAttr()

  //2：首页数据渲染
  axios.get('http://139.9.177.51:8099/headPageInfo',{
    params:{
      userId:localStorage.getItem('userId')
    }
  }).then(function(res){
    if(res.data.status === 0){
      rank.textContent = res.data.data.rank;
      punchDay.textContent = res.data.data.punchIn;
      badge.textContent = res.data.data.insigniaNum;
      // todayPunch.textContent = res.data.data.rank;
      res.data.data.isPunch === 'true' ? todayPunch.textContent = '已打卡' : todayPunch.textContent = '今日打卡'
    }
  })
  // 3:今日打卡
  todayPunch.addEventListener('click',function(){
    axios.get('http://139.9.177.51:8099/clockIn',{
      params:{
        userId:localStorage.getItem('userId')
      }
    }).then(function(res){
      if(res.data.status === 0){
        punchDay.textContent++;
        todayPunch.textContent  = '已打卡'
        weui.toast('打卡成功',1000)
      }else{
        weui.toast('已打卡',1000)
      }
    })
  })
})
